//
//  MainViewController.m
//  LClass
//
//  Created by 严军 on 16/6/3.
//  Copyright © 2016年 YanJun. All rights reserved.
//

#import "MainViewController.h"
#import "MainView.h"
#import "StatisticViewController.h"
#import "QQRequestManager+handle.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    NSDictionary* dataDic=@{@"allStuNum":@"3",@"kaoQinNum":@"3",@"kaoQinList":
//                                @[
//                                    @{@"studentName":@"张华丽",
//                                      @"stunumber":@"20130647",
//                                      @"academyName":@"理学与信息科学学院",
//                                      @"professName":@"电子信息科学与技术",
//                                      @"className":@"2013级01班",
//                                      @"studentId":@3,
//                                      @"courseId":@5,
//                                      @"classId":@3}
//                                    ]
//                                
//                                };
    
    MainView* mainV=[[MainView alloc]initWithDataList:_dataDic];
    self.view=mainV;
    __block MainViewController* blockSelf=self;
    mainV.finishiBlock=^(NSDictionary*paraDic){
        //提交考勤数据
        [blockSelf submitData:paraDic];
        
    };
    //mainV.dataList=@[@{@"name":@"张华丽"},@{@"name":@"张华丽"},@{@"name":@"张华丽"}];
}

-(void)submitData:(NSDictionary*)dataDic
{
    NSMutableArray* dataParamAry=[[NSMutableArray alloc]init];
    NSArray* ary=[dataDic objectForKey:@"kaoqinData"];
    for (NSDictionary* dic in ary) {
        int mark=[(NSNumber*)[dic objectForKey:@"state"] intValue]-1;
        [dataParamAry addObject:@{@"studentId":[dic objectForKey:@"studentId"],
                                  @"courseId":[dic objectForKey:@"courseId"],
                                  @"mark":[NSNumber numberWithInt:mark]
                                  }];
    }
    NSString* jsonStr=[[Utility sharedInstance] DataToJsonString:@{@"list":dataParamAry}];
    __block MainViewController* blockSelf=self;
    [[QQRequestManager sharedRequestManager] GET_submitCheckDataWithParameters:@{@"paraMap":jsonStr} success:^(NSURLSessionDataTask *task, id responseObject) {
        int status=[(NSNumber*)[responseObject objectForKey:@"status"] intValue];
        if (status==1) {
            [blockSelf qq_performSVHUDBlock:^{
                [SVProgressHUD showSuccessWithStatus:[responseObject objectForKey:@"message"]];
            }];
            NSMutableDictionary* backDic=[[NSMutableDictionary alloc]initWithDictionary:dataDic];
            [backDic setObject:[responseObject objectForKey:@"absenceNum"] forKey:@"allAbsenceStuNums"];//缺课人次
            [backDic setObject:[responseObject objectForKey:@"checkCount"] forKey:@"allCheckCount"];//考勤次数
            [backDic setObject:[responseObject objectForKey:@"courseNum"] forKey:@"chooseCourseStuNum"];//选课人数
            [backDic setObject:[responseObject objectForKey:@"perofClass"] forKey:@"allArriveRate"];//到课率
            [backDic setObject:[responseObject objectForKey:@"perofMiss"] forKey:@"allAbsenceRate"];//缺课率
            [backDic setObject:[responseObject objectForKey:@"inclassNum"] forKey:@"allArriveNum"];//到课人次
            //考勤完毕后返回考勤数据
            StatisticViewController* statisticVC=[[StatisticViewController alloc]init];
            statisticVC.dataDic=backDic;
            [blockSelf.navigationController pushViewController:statisticVC animated:YES];
            
        }else
        {
            [blockSelf qq_performSVHUDBlock:^{
                [SVProgressHUD showErrorWithStatus:[responseObject objectForKey:@"message"]];
            }];

        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [blockSelf qq_performSVHUDBlock:^{
            [SVProgressHUD showErrorWithStatus:@"服务器错误！"];
        }];

    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
